﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Styx;
using Styx.Common;

namespace MIBWarlock
{
    public partial class MIBWarlockGUI : Form
    {
        public MIBWarlockGUI()
        {
            InitializeComponent();
        }

        #region Load

        private void MIBWarlockGUI_Load(object sender, EventArgs e)
        {
            if (Classname.GetCurrentSpec() == "Demonology" && !StyxWoW.Me.Name.Contains("Windu"))
            {
                tabControl1.TabPages.Remove(tabPage3);
                tabControl1.TabPages.Remove(tabPage4);
            }
            else if (Classname.GetCurrentSpec() == "Affliction" && !StyxWoW.Me.Name.Contains("Windu"))
            {
                tabControl1.TabPages.Remove(tabPage2);
                tabControl1.TabPages.Remove(tabPage4);
            }
            else if (Classname.GetCurrentSpec() == "Destruction" && !StyxWoW.Me.Name.Contains("Windu"))
            {
                tabControl1.TabPages.Remove(tabPage2);
                tabControl1.TabPages.Remove(tabPage3);
            }
            else if (!StyxWoW.Me.Name.Contains("Windu"))
            {
                tabControl1.TabPages.Remove(tabPage2);
                tabControl1.TabPages.Remove(tabPage3);
                tabControl1.TabPages.Remove(tabPage4);
            }

            AoEKey.SelectedIndex = MIBSettings.Instance.AoEKey;
            AttackOOC.Checked = MIBSettings.Instance.AttackOOC;
            AutoMove.Checked = MIBSettings.Instance.AutoMove;
            AutoFace.Checked = MIBSettings.Instance.AutoFace;
            AutoBuff.Checked = MIBSettings.Instance.AutoBuff;
            AutoRacial.Checked = MIBSettings.Instance.AutoRacial;
            AutoTarget.Checked = MIBSettings.Instance.AutoTarget;
            BurstKey.SelectedIndex = MIBSettings.Instance.BurstKey;
            BurstHP.Value = MIBSettings.Instance.BurstHP;
            DarkRegenerationPetHP.Value = MIBSettings.Instance.DarkRegenerationPetHP;
            DarkRegenerationPlayerHP.Value = MIBSettings.Instance.DarkRegenerationPlayerHP;
            HealthStone.Checked = MIBSettings.Instance.HealthStone;
            HealthStoneHP.Value = MIBSettings.Instance.HealthStoneHP;
            PauseKey.SelectedIndex = MIBSettings.Instance.PauseKey;
            ProfBuff.SelectedIndex = MIBSettings.Instance.ProfBuff;
            ProfBuffHP.Value = MIBSettings.Instance.ProfBuffHP;
            StartEating.Value = MIBSettings.Instance.StartEating;
            Trinket1.SelectedIndex = MIBSettings.Instance.Trinket1;
            Trinket1HP.Value = MIBSettings.Instance.Trinket1HP;
            Trinket2.SelectedIndex = MIBSettings.Instance.Trinket2;
            Trinket2HP.Value = MIBSettings.Instance.Trinket2HP;
            UseFoodDrink.Checked = MIBSettings.Instance.UseFoodDrink;
        }

        #endregion

        public string LastSavedMode = "";

        private void OK_Click(object sender, EventArgs e)
        {
            MIBSettings.Instance.LastSavedMode = LastSavedMode;
            MIBSettings.Instance.LastSavedSpec = Classname.GetCurrentSpec();
            MIBSettings.Instance.Save();
            Logging.Write("----------------------------------");
            Logging.Write("MIBWarlock Settings wurden gespeichert");
            Close();

            MIBSettings.Instance.UpdateStatus = true;
        }

        private void BurstHP_ValueChanged(object sender, EventArgs e)
        {
            MIBSettings.Instance.BurstHP = (int)BurstHP.Value;
        }

        private void ProfBuffHP_ValueChanged(object sender, EventArgs e)
        {
            MIBSettings.Instance.ProfBuffHP = (int)ProfBuffHP.Value;
        }

        private void Trinket1HP_ValueChanged(object sender, EventArgs e)
        {
            MIBSettings.Instance.Trinket1HP = (int)Trinket1HP.Value;
        }

        private void Trinket2HP_ValueChanged(object sender, EventArgs e)
        {
            MIBSettings.Instance.Trinket2HP = (int)Trinket2HP.Value;
        }

        private void BurstKey_SelectedIndexChanged(object sender, EventArgs e)
        {
            for (var i = 0; i <= 46; i++)
            {
                if (BurstKey.SelectedIndex == i)
                {
                    MIBSettings.Instance.BurstKey = i;
                }
            }
        }

        private void ProfBuff_SelectedIndexChanged(object sender, EventArgs e)
        {
            for (var i = 0; i <= 8; i++)
            {
                if (ProfBuff.SelectedIndex == i)
                {
                    MIBSettings.Instance.ProfBuff = i;
                }
            }
        }

        private void Trinket1_SelectedIndexChanged(object sender, EventArgs e)
        {
            for (var i = 0; i <= 8; i++)
            {
                if (Trinket1.SelectedIndex == i)
                {
                    MIBSettings.Instance.Trinket1 = i;
                }
            }
        }

        private void Trinket2_SelectedIndexChanged(object sender, EventArgs e)
        {
            for (var i = 0; i <= 8; i++)
            {
                if (Trinket2.SelectedIndex == i)
                {
                    MIBSettings.Instance.Trinket2 = i;
                }
            }
        }

        private void AttackOOC_CheckedChanged(object sender, EventArgs e)
        {
            MIBSettings.Instance.AttackOOC = AttackOOC.Checked;
        }

        private void AutoFace_CheckedChanged(object sender, EventArgs e)
        {
            MIBSettings.Instance.AutoFace = AutoFace.Checked;
        }

        private void AutoRacial_CheckedChanged(object sender, EventArgs e)
        {
            MIBSettings.Instance.AutoRacial = AutoRacial.Checked;
        }

        private void UseFoodDrink_CheckedChanged(object sender, EventArgs e)
        {
            MIBSettings.Instance.UseFoodDrink = UseFoodDrink.Checked;
        }

        private void AutoBuff_CheckedChanged(object sender, EventArgs e)
        {
            MIBSettings.Instance.AutoBuff = AutoBuff.Checked;
        }

        private void AutoMove_CheckedChanged(object sender, EventArgs e)
        {
            MIBSettings.Instance.AutoMove = AutoMove.Checked;
        }

        private void AutoTarget_CheckedChanged(object sender, EventArgs e)
        {
            MIBSettings.Instance.AutoTarget = AutoTarget.Checked;
        }

        private void StartEating_ValueChanged(object sender, EventArgs e)
        {
            MIBSettings.Instance.StartEating = (int)StartEating.Value;
        }

        private void PauseKey_SelectedIndexChanged(object sender, EventArgs e)
        {
            for (var i = 0; i <= 40; i++)
            {
                if (PauseKey.SelectedIndex == i)
                {
                    MIBSettings.Instance.PauseKey = i;
                }
            }
        }

        private void AoEKey_SelectedIndexChanged(object sender, EventArgs e)
        {
            for (var i = 0; i <= 40; i++)
            {
                if (AoEKey.SelectedIndex == i)
                {
                    MIBSettings.Instance.AoEKey = i;
                }
            }
        }

        private void HealthStoneHP_ValueChanged(object sender, EventArgs e)
        {
            MIBSettings.Instance.HealthStoneHP = (int)HealthStoneHP.Value;
        }

        private void HealthStone_CheckedChanged(object sender, EventArgs e)
        {
            MIBSettings.Instance.HealthStone = HealthStone.Checked;
        }

        private void DarkRegenerationPlayerHP_ValueChanged(object sender, EventArgs e)
        {
            MIBSettings.Instance.DarkRegenerationPlayerHP = (int)DarkRegenerationPlayerHP.Value;
        }

        private void DarkRegenerationPetHP_ValueChanged(object sender, EventArgs e)
        {
            MIBSettings.Instance.DarkRegenerationPetHP = (int)DarkRegenerationPetHP.Value;
        }
    }
}
